package com.sims.action.general;

import org.springframework.beans.factory.annotation.Autowired;

import com.sims.bean.Manager;
import com.sims.bean.Student;
import com.sims.bean.Teacher;
import com.sims.service.ManagerService;
import com.sims.service.StudentService;
import com.sims.service.TeacherService;
import com.sims.util.ActionEnhanced;
import com.sims.util.Constant;
import com.sun.org.apache.bcel.internal.generic.RETURN;

public class LoginAction extends ActionEnhanced{
	
	private String userNo;
	private String password;
	private String userType;
	private Student student = new Student();
	private Teacher teacher = new Teacher();
	private Manager manager = new Manager();
	@Autowired
	private StudentService studentService;
	@Autowired
	private TeacherService teacherService;
	@Autowired
	private ManagerService managerService;
	
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	public Teacher getTeacher() {
		return teacher;
	}
	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
	public Manager getManager() {
		return manager;
	}
	public void setManager(Manager manager) {
		this.manager = manager;
	}
	public String getUserNo() {
		return userNo;
	}
	public void setUserNo(String userNo) {
		this.userNo = userNo;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUserType() {
		return userType;
	}
	public void setUserType(String userType) {
		this.userType = userType;
	}
	
	@Override
	public String execute() {
		
		System.out.println(userType);
		if (userType.equals(Constant.STUDENT)) {
			student.setSno(userNo);
			student.setPassword(password);
			result = studentService.studentLogin(student);
			if ( result.containsKey(SUCCESS) )
					return "studentLogin";
			else return ERROR;
		}
		else if (userType.equals(Constant.TEACHER)) {
			teacher.setTno(userNo);
			teacher.setPassword(password);
			result = teacherService.teacherLogin(teacher);
			if ( result.containsKey(SUCCESS) )
				return "teacherLogin";
			else return ERROR;
		}
		else {
			manager.setMno(userNo);
			manager.setPassword(password);
			result = managerService.manageLogin(manager);
			if ( result.containsKey(SUCCESS) )
				return "managerLogin";
			else return ERROR;
		}
	}
	
}
